package com.fjnldx.mes.config;

import io.swagger.annotations.Api;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@ConditionalOnProperty(prefix = "mconfig", name = "swagger-ui-open", havingValue = "true")
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Hello！Mes-Server")
                .description("Rest API接口")
                .termsOfServiceUrl("http://39.108.91.47:8080/dist/")
                .version("2.0")
                .build();
    }

    @Bean("Mes模块")
    public Docket controller1Apis() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("转转").select().apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.regex("/secondhand/.*"))
                .build()
                .apiInfo(apiInfo())
                .enable(true);
    }
    @Bean("公共模块")
    public Docket controller1Apis2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("公共模块").select().apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.regex("/common/.*"))
                .build()
                .apiInfo(apiInfo())
                .enable(true);
    }
}
